﻿﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PMSSys
{
    public partial class BoneMarrowReadingView : Form
    {
        public BoneMarrowReadingView(bmaController bmaCtrl, string bmaID, int p_id)
        {
            InitializeComponent();
            bmaCtrller = bmaCtrl;
            bonema = new BMA();
            this.p_id = p_id;
            if (String.IsNullOrEmpty(bmaID))
            {
                addMode = true;
                this.Text = "Add Bone Marrow Reading";
            }
            else
            {
                this.Text = "View Bone Marrow Reading";
                bonema.BmaID = int.Parse(bmaID);
                this.bmaID = bonema.BmaID;
                bmaCtrller.objectFiller(bonema);
                dpBMA.Value = bonema.BmaDate;
                tbBoneMarrow.Text = bonema.RepBSTR;
                tbClinicalAbstract.Text = bonema.ClinAbst;
                tbReview.Text = bonema.RevPRS;
                tbInterpretation.Text = bonema.Interpretation;
                isModified = false;
            }
        }
        private void modifyChecker(object sender, EventArgs e)
        {
            isModified = true;
        }
        private bool isModified = false;
        private bool addMode;
        private bmaController bmaCtrller;
        private int bmaID, p_id;
        private BMA bonema;
        private void closeLogic(object sender, EventArgs e)
        {
            this.Close();

        }

        private void BoneMarrowReadingView_FormClosing(object sender, FormClosingEventArgs e)
        {        
            if (isModified)
            {
                DialogResult res = uiUtility.confirmSaveDialog();
                if (res != DialogResult.Cancel)
                {
                    if (res == DialogResult.Yes)
                    {
                       DateTime dateNow = DateTime.Now;
                       int cmpDate = DateTime.Compare(dpBMA.Value,dateNow);
                       if (cmpDate <= 0)
                       {
                           if (addMode)
                           {
                               bmaCtrller.addBma(addAttributes());
                           }
                           else
                           {
                               bmaCtrller.updateBma(addAttributes());
                           }
                       }
                       else
                       {
                           DialogResult validDate = uiUtility.validDate("Bone Marrow Reading Date");
                           e.Cancel = true;
                       }                         
                    }

                }
                else
                    e.Cancel = true;
            }
        }

        private void BoneMarrowReadingView_Load(object sender, EventArgs e)
        {
            ToolTip t1 = uiUtility.tooltips();
            t1.SetToolTip(this.button6, "Back");
        }
        private BMA addAttributes()
        {
           
            bonema.PatientID = this.p_id;
            bonema.BmaDate = dpBMA.Value;
            bonema.ClinAbst = tbClinicalAbstract.Text;
            bonema.RevPRS = tbReview.Text;
            bonema.RepBSTR = tbBoneMarrow.Text;
            bonema.Interpretation = tbInterpretation.Text;
            bonema.BmaID = bmaID;
            return bonema;
        }
    }
}